home *** CD-ROM | disk | FTP | other *** search
/ BBS Toolkit / BBS Toolkit.iso / maximus / mxms_161.zip / INIT.C < prev    next >
C/C++ Source or Header  |  1991-07-26  |  30KB  |  984 lines

  1. /****************************************************************************/
  2. /*    Init.c      MaxMail initialization stuff                              */
  3. /*                                                                          */
  4. /****************************************************************************/
  5.  
  6. #include "MaxMail.h"
  7.  
  8. char dummy[81];
  9. char adrive[_MAX_DRIVE];
  10.  
  11. extern int  fido_init;
  12. extern int Command;
  13. extern char  _far *msgbuffer;
  14.  
  15. /* Initialize MaxMail */
  16.  
  17. void _pascal init()
  18. {
  19.  
  20.    int x;
  21.    struct find_t fbuf;
  22.  
  23.    startsecs = clock();
  24.    parmread = FALSE;
  25.    get_currents();           /* Get the current directory,drive and save */
  26.  
  27.    LogMode = 0;        /* Turn off logging by default */
  28.  
  29.    NewHelpFil[0] = 0;        /* Turn off newusers help file */
  30.    HelpFile[0] = 0;        /* Turn off std help file */
  31.    LogFile[0] = 0;        /* Turn Off logfile by default */
  32.    SignOff[0] = 0;
  33.    MsgHdrFile[0] = 0;
  34.    statline[0] = 0;
  35.    BullFile[0] = 0;
  36.    BBSid[0] = 0;
  37.    QWKWelcome[0] = 0;
  38.    QWKnews[0] = 0;
  39.    QWKbye[0] = 0;
  40.    QWKDir[0] = 0;
  41.    NewFiles[0] = 0;
  42.    Command = FALSE;
  43.    strcpy(BBSphone,"555-1212");
  44.    tdir[0] = 0;        /* Temporary directory for Packing program */
  45.    PACKER_1 = NULL;
  46.    PROTO_1  = NULL;
  47.    ZIPREP = NULL;
  48.    LHAREP = NULL;
  49.    ARCREP = NULL;
  50.    ExtendOk = TRUE;
  51.    ReDirect = FALSE;
  52.    MaxDaily = 0;
  53.    StripTags = TRUE;
  54.  
  55.    SkipCount = 0;
  56.    ForceCount = 0;
  57.  
  58. /* Establish Default color attributes */
  59.  
  60.    TextAttr[STD_TEXT] = 6;           /* Cyan on black */
  61.    TextAttr[HILITE_TEXT] = 3;        /* Yellow on black */
  62.    TextAttr[MENU_KEY] = 2;        /* Green on black */
  63.    TextAttr[TIME_LEFT] = 87;        /* White on Magenta */
  64.    TextAttr[PROMPT_TEXT] = 4;        /* Blue on black */
  65.    TextAttr[ATTN_TEXT] = 1;        /* Red on black */
  66.    TextAttr[VIEW_TEXT] = 71;        /* White on Blue */
  67.  
  68.    load_cfgfile(MCfgFile);
  69.  
  70.    if (tdir[0]) {        /* Was a temp dir specified? */
  71.       x = strlen(tdir) - 1;        /* Bump to tail end of string */
  72.       if (tdir[x] == '\\')
  73.          tdir[x] = 0;        /* Remove it! We will add it when necessary */
  74.    }
  75.  
  76.    if (Task && LogFile[0]) {        /* Redo logfile name with task # */
  77.       _splitpath(LogFile,adrive,dummy,temp,temp1);
  78.       temp[6] = 0;        /* Trim out 2 chars */
  79.       sprintf(LogFile,"%s%s%s%02x%s",adrive,dummy,temp,Task,temp1);
  80.    }
  81.  
  82.    if (!parmread) {
  83.       if(read_prm(PrmFile) < 0)
  84.          aborterror(FILEOPEN,"Error opening PRM file!\r\n");
  85.  
  86.       if(switch_dir(PRM(sys_path)))        /* Change to Maximus home dir */
  87.          deinit(2);
  88.    }
  89.  
  90. /* Now test the temp subdirectory and see if it's legal */
  91.    if (tdir[0]) {
  92.       if (switch_dir(tdir)) {        /* Uh oh! */
  93.          logit("Invalid temp dir specified",'!');
  94.          tdir[0] = 0;        /* Terminate it! */
  95.       }
  96.       switch_dir(PRM(sys_path));        /* Return to Maximus root */
  97.    }
  98.  
  99.    if (IsLocal >= 2) 
  100.       MaxMsgs = 9999;        /* Allow tons of messages in local mode */
  101.  
  102.    sprintf(temp,"MxMlAct.%03x",Task);        /* Create a task id */
  103.    x = sopen(temp,O_RDWR | O_BINARY | O_CREAT,SH_DENYWR,S_IWRITE);
  104.    close(x);        /* Create just a null file */
  105.  
  106.    if (Task && SumFile[0]) {
  107.       sprintf(temp,".%03x",Task);
  108.       strcat(SumFile,temp);
  109.    }
  110.  
  111.    /* See if helpfile exists */
  112.    if (_dos_findfirst(HelpFile,_A_NORMAL,&fbuf) && HelpFile[0])
  113.       HelpFile[0] = 0;        /* Disable */
  114.  
  115. }
  116.  
  117. /* Close up MaxMail, clean up loose ends */
  118. void _pascal deinit(int errcode)
  119. {
  120.    int x,y,z;
  121.    long secdiff;
  122.    struct _restart *rst;
  123.    struct find_t fbuf;
  124.  
  125.    if (fido_init)
  126.       _ffree(msgbuffer);
  127.  
  128.    switch_dir(PRM(sys_path));        /* Return to Maximus root */
  129.  
  130.    if (tdir[0])
  131.       switch_dir(tdir);
  132.  
  133.    if (QWKDir[0])
  134.       if(chdir(QWKDir) != 0)
  135.          QWKDir[0] = 0;
  136.  
  137.    if(packer_del) 
  138.       unlink(ArcFile);
  139.  
  140.    if (USERCFG.msgfrmt == 1) {
  141.       if (QWKDir[0]) {        /* We are in private subdir */
  142.          if (IsLocal) {        /* We gotta keep qwk file! */
  143.             sprintf(temp,"%s.qwk",BBSid);
  144.             chmod(temp,S_IREAD);    /* Thus make it read only */
  145.          }
  146.          if (!_dos_findfirst("*.*",_A_NORMAL,&fbuf)) {    /* Kill everything in subdir */
  147.             unlink(fbuf.name);
  148.             while (!_dos_findnext(&fbuf)) 
  149.                unlink(fbuf.name);
  150.          }
  151.          if (IsLocal)         /* We gotta keep qwk file! */
  152.             chmod(temp,S_IWRITE);    /* restore it */
  153.       }
  154.       else {        /* Try to do a decent cleanup */
  155.          sprintf(temp,"%s.rep",BBSid);
  156.          unlink(temp);
  157.          unlink("control.dat");
  158.          unlink("messages.dat");
  159.          unlink("NewFiles.dat");
  160.          unlink("Door.id");
  161.  
  162.          _splitpath(QWKnews,dummy,dummy,temp,temp1);
  163.          sprintf(dummy,"%s%s",temp,temp1);
  164.          unlink(dummy);        /* Kill all the special files */
  165.  
  166.          _splitpath(QWKbye,dummy,dummy,temp,temp1);
  167.          sprintf(dummy,"%s%s",temp,temp1);
  168.          unlink(dummy);        /* Kill all the special files */
  169.  
  170.          _splitpath(QWKWelcome,dummy,dummy,temp,temp1);
  171.          sprintf(dummy,"%s%s",temp,temp1);
  172.          unlink(dummy);        /* Kill all the special files */
  173.  
  174.          if (!_dos_findfirst("???.ndx",_A_NORMAL,&fbuf)) {
  175.             unlink(fbuf.name);
  176.             while (!_dos_findnext(&fbuf)) 
  177.                unlink(fbuf.name);
  178.          }
  179.          if (!_dos_findfirst("blt-*.*",_A_NORMAL,&fbuf)) {
  180.             unlink(fbuf.name);
  181.             while (!_dos_findnext(&fbuf)) 
  182.                unlink(fbuf.name);
  183.          }
  184.       }
  185.    }
  186.    else {
  187.       unlink(TxtFile);
  188.       unlink(StatName);
  189.    }
  190.  
  191.  
  192.    if(QWKDir[0]) {
  193.       chdir("..");
  194.       rmdir(QWKDir);        /* Remove temp directory */
  195.       QWKDir[0] = 0;
  196.    }
  197.  
  198.    homedir();
  199.  
  200.    x = USRCFG_UPD | USRCFG_FUPD | USRCFG_MSGUPD;
  201.    x ^= 0xffff;
  202.    USERCFG.flags &= x;        /* Turn off forced update flags */
  203.  
  204.    if (newuser) {
  205.       printf("Building new user message areas\n");
  206.       build_areas(FALSE,FALSE);        /* Recalc totareas */
  207.    }
  208.  
  209.    sprintf(temp,"MxMlAct.%03x",Task);        /* Create a task id */
  210.    unlink(temp);
  211.    if (!SysopMode) {
  212.       x = sopen(CfgFile,O_RDWR | O_BINARY,SH_DENYWR,S_IWRITE);
  213.       if (x != -1) {
  214.          time(&USERCFG.lasttime);
  215.          USERCFG.totprotos = totprotocols;
  216.          USERCFG.totpackers = totpackers;
  217.          USERCFG.calls++;
  218.          strcpy(USERCFG.name,LastUser.name);
  219.          if (USERCFG.calls < USERCFG.packcount)
  220.             USERCFG.calls = USERCFG.packcount;
  221.          update_usercfg(x);
  222.          close(x);
  223.       }
  224.       else logit("Error updating User Config file",'!');
  225.       sprintf(temp,"%s off-line. Calls=%u, Len=%u",UserName,USERCFG.calls,timeon());
  226.    }
  227.    else {
  228.       sprintf(temp,"Local Sysop off-line. Calls=~, Len=~");
  229.       errcode = 7;
  230.    }
  231.    logit(temp,':');
  232.    sprintf(temp,"End, (%d)",errcode);
  233.    logit(temp,':');
  234.  
  235.    if (LogFile[0]) {
  236.       x = sopen(LogFile,O_BINARY | O_RDWR | O_APPEND,SH_DENYWR,S_IWRITE);
  237.       if (x > 0) {
  238.          write(x,"\r\n",2);
  239.          close(x);
  240.       }
  241.    }
  242.  
  243.    if (TimeAdjust) {
  244.       sprintf(temp,"Restar%02x.bbs",Task); 
  245.       if(_dos_findfirst(temp,_A_NORMAL,&fbuf) == 0 ) { 
  246.          rst = (struct _restart *) malloc(sizeof(struct _restart));
  247.          if (rst != NULL) {
  248.             x = sopen(temp,O_BINARY | O_RDWR,SH_DENYWR,S_IWRITE);
  249.             if (x != -1) {
  250.                if(read(x,(char *)rst,sizeof(struct _restart)) != 0) {
  251.                   secdiff = rst->timeoff - rst->timeon;
  252.                   z = (int) (secdiff / 60L);        /* convert to minutes */
  253.                   y = timeon();
  254.                   if ((unsigned long)(y + z) <= rst->max_time){ /* We can bump it up */
  255.                      rst->timeoff += 60 * timeon();
  256.                      rst->timeon += 60 * timeon();
  257.                   }
  258.                   lseek(x,0L,SEEK_SET);        /* Rewind the file */
  259.                   write(x,(struct _restart *) rst,sizeof(struct _restart));
  260.                }
  261.                close(x);
  262.             }
  263.          }
  264.       }
  265.       else {        /* RestarXX doesn't exist so we muck LastUser instead */
  266.          x = sopen(LastUse,O_RDWR | O_BINARY ,SH_DENYWR,S_IWRITE); 
  267.          if (x != -1) {
  268.             lseek(x,0L,SEEK_SET);        /* Rewind the file */
  269.             LastUser.timeremaining += timeon();
  270.             write(x,(char *) &LastUser,user_slen);
  271.             close(x);
  272.          }
  273.       }
  274.    }
  275.  
  276.    fclose(afile);
  277.    sprintf(temp,"%s%s",sdrive,sdir);
  278.    switch_dir(temp);        /* Change back to startup dir */
  279.    FossilDeInit();
  280.    setcolor(TextAttr[STD_TEXT]);
  281.    exit(errcode);
  282. }
  283.  
  284. void _pascal aborterror(int code,char *strng)
  285. {
  286.    int exitcode;
  287.  
  288.    fclose(outfile);
  289.    exitcode = 1;
  290.  
  291.  
  292.    switch (code) {
  293.       case BADALLOC:
  294.          strcpy(temp,"Error allocating memory");
  295.          break;
  296.  
  297.       case BADEXEC:
  298.          strcpy(temp,"Error executing external program");
  299.          break;
  300.  
  301.       case FILEOPEN:
  302.          strcpy(temp,"Error opening file");
  303.          exitcode = 4;
  304.          break;
  305.  
  306.       case FILECREATE:
  307.          strcpy(temp,"Error creating file");
  308.          exitcode = 4;
  309.          break;
  310.  
  311.       case FILEWRITE:
  312.          strcpy(temp,"Error writing file");
  313.          exitcode = 4;
  314.          break;
  315.  
  316.       case DROPCARRIER:
  317.          strcpy(temp,"User dropped carrier!");
  318.          IsLocal = TRUE;
  319.          exitcode = 3;
  320.          break;
  321.  
  322.       case DEADMODEM:
  323.          strcpy(temp,"Modem output appears dead!");
  324.          IsLocal = TRUE;
  325.          exitcode = 3;
  326.          break;
  327.  
  328.       case USERIDLE:
  329.          sprintf(temp,"User was idle more than %d minutes!",IDLETIME);
  330.          IsLocal = TRUE;
  331.          exitcode = 3;
  332.          break;
  333.  
  334.       default:
  335.          strcpy(temp,"General failure");
  336.          break;
  337.    }
  338.  
  339.    if (code != DEADMODEM) {
  340.  
  341.       setcolor(TextAttr[ATTN_TEXT]);
  342.       strout("\r\n");
  343.       if (strng)  {
  344.          strout(strng);
  345.          logit(strng,'!');
  346.       }
  347.       else {
  348.          strout(temp);
  349.          logit(temp,'!');
  350.       }
  351.       strout("\r\n");
  352.       setcolor(TextAttr[STD_TEXT]);
  353.    }
  354.    else logit(strng,'!');
  355.  
  356.    deinit(exitcode);
  357. }
  358.  
  359. int _pascal load_cfgfile(char *cfgfile)
  360. {
  361.    FILE *cfile;
  362.    char *p1,*p2,*p3;
  363.    int x,y;
  364.  
  365.    cfile = _fsopen(cfgfile,"rt",SH_DENYNO);
  366.    if (cfile == NULL) {        /* Try to open it in executable maxmail dir */
  367.       _splitpath(cfgfile,dummy,dummy,temp,temp1);        /* Extract just filename */
  368.       _makepath(dummy,hdrive,hdir,temp,temp1);
  369.       cfile = _fsopen(dummy,"rt",SH_DENYNO);
  370.       if (cfile == NULL) {        /* Not there? Then its hopeless! */
  371.          sprintf(temp1,"Error opening '%s' config file!\r\n",dummy);
  372.          aborterror(FILEOPEN,temp1);
  373.       }
  374.    }
  375.  
  376.    fgets(temp,81,cfile);
  377.    while (!feof(cfile)) {
  378.       if (*temp != '\0') {        /* Parse out token string */
  379.          p1 = strtok(temp," \n\t");
  380.          p2 = strtok(NULL," \n\t;");
  381.          if (strcmpi(p1,";") == 0) {        /* Just ignore comment lines */
  382.             fgets(temp,81,cfile);
  383.             continue;
  384.          }
  385.          if (strcmpi(p1,"TxtFile") == 0) {
  386.             if (p2) strcpy(TxtFile,p2);
  387.          }
  388.          else if (strcmpi(p1,"CfgFile") == 0) {
  389.             if (p2) strcpy(CfgFile,p2);
  390.          }
  391.          else if (strcmpi(p1,"LogFile") == 0) {
  392.             if (p2) strcpy(LogFile,p2);
  393.             LogMode = VERBOSE;        /* Default mode */
  394.          }
  395.          else if (strcmpi(p1,"NewHelpFile") == 0) {
  396.             if (p2) strcpy(NewHelpFil,p2);
  397.          }
  398.          else if (strcmpi(p1,"HelpFile") == 0) {
  399.             if (p2) strcpy(HelpFile,p2);
  400.          }
  401.          else if (strcmpi(p1,"MaximumMessages") == 0) {
  402.             if (p2) MaxMsgs = atoi(p2);
  403.          }
  404.          else if (strcmpi(p1,"MessageHeader") == 0) {
  405.             if (p2) strcpy(MsgHdrFile,p2);
  406.          }
  407.          else if (strcmpi(p1,"NewFilesList") == 0) {
  408.             if (p2) strcpy(NewFiles,p2);
  409.          }
  410.          else if (strcmpi(p1,"SignOutMsg") == 0) {
  411.             x = 0;
  412.             p3 = strtok(p2," ;_\n\t");
  413.             while (p3) {
  414.                x += strlen(p3);
  415.                strncat(SignOff,p3,79);
  416.                strcat(SignOff," ");
  417.                p3 = strtok(NULL," ;_\n\t");
  418.                if (strlen(SignOff) >= 80)
  419.                   break;
  420.             }
  421.          }
  422.          else if (strcmpi(p1,"Packer") == 0) {
  423.             x = 0;
  424.             temp1[0] = '\0';
  425.             while (p2) {
  426.                strcat(temp1,p2);        /* Description string */
  427.                strcat(temp1," ");        /* Add a blank for safety */
  428.                if (++x > 4)        /* Packer requires 4 parameter fields */
  429.                   break;
  430.                p2 = strtok(NULL," ;\n\t");
  431.             }
  432.             if (x >= 4) enable_packer(temp1);
  433.          }
  434.          else if (strcmpi(p1,"Protos") == 0) {
  435.             x = 0;
  436.             temp1[0] = '\0';
  437.             while (p2) {
  438.                strcat(temp1,p2);        /* Description string */
  439.                strcat(temp1," ");        /* Add a blank for safety */
  440.                if (++x >= 3)        /* Packer requires 3 parameter fields */
  441.                   break;
  442.                p2 = strtok(NULL," ;\n\t");
  443.             }
  444.             if (x >= 3) enable_proto(temp1);
  445.          }
  446.          else if (strcmpi(p1,"RepUpload") == 0) {
  447.             x = 0;
  448.             temp1[0] = '\0';
  449.             while (p2) {
  450.                strcat(temp1,p2);        /* Description string */
  451.                strcat(temp1," ");        /* Add a blank for safety */
  452.                if (++x >= 3)        /* Packer requires 3 parameter fields */
  453.                   break;
  454.                p2 = strtok(NULL," ;\n\t");
  455.             }
  456.             if (x >= 3) enable_upl(temp1);
  457.          }
  458.          else if (strcmpi(p1,"SkipAreas") == 0) {
  459.             strcpy(temp1,p2);        /* Copy area numbers */
  460.             p2 = strtok(temp1,", \t");
  461.             y = 1;
  462.             while (p2) {
  463.                if (!SkipCount)
  464.                   SkipAreas = (int **) calloc(1,sizeof(int *));
  465.                else SkipAreas = (int **) realloc(SkipAreas,sizeof(int *) * (y+1));
  466.                if (SkipAreas == NULL)
  467.                   aborterror(BADALLOC,NULL);
  468.                SkipAreas[y-1] = (int *) malloc(sizeof(int));
  469.                if (SkipAreas[y-1] == NULL)
  470.                   aborterror(BADALLOC,NULL);
  471.                *(SkipAreas[y-1]) = atoi(p2);        /* Plug in the area number */
  472.                y++;
  473.                SkipCount++;
  474.                p2 = strtok(NULL,", \t");
  475.             }
  476.          }
  477.          else if (strcmpi(p1,"ForceAreas") == 0) {
  478.             strcpy(temp1,p2);        /* Copy area numbers */
  479.             p2 = strtok(temp1,", \t");
  480.             y = 1;
  481.             while (p2) {
  482.                if (!ForceCount)
  483.                   ForceAreas = (int **) calloc(1,sizeof(int *));
  484.                else ForceAreas = (int **) realloc(ForceAreas,sizeof(int *) * (y+1));
  485.                if (ForceAreas == NULL)
  486.                   aborterror(BADALLOC,NULL);
  487.                ForceAreas[y-1] = (int *) malloc(sizeof(int));
  488.                if (ForceAreas[y-1] == NULL)
  489.                   aborterror(BADALLOC,NULL);
  490.                *(ForceAreas[y-1]) = atoi(p2);        /* Plug in the area number */
  491.                y++;
  492.                ForceCount++;
  493.                p2 = strtok(NULL,", \t");
  494.             }
  495.          }
  496.          else if (strcmpi(p1,"TempDir") == 0) {
  497.             if (p2) strcpy(tdir,p2);
  498.          }
  499.          else if (strcmpi(p1,"ExtendedBarrier") == 0) {
  500.             if (p2) {
  501.                if(strcmpi(p2,"yes") == 0)
  502.                   ExtendOk = TRUE;
  503.                else ExtendOk = FALSE;
  504.             }
  505.          }
  506.          else if (strcmpi(p1,"WatchDog") == 0) {
  507.             if (p2) {
  508.                if(strcmpi(p2,"yes") == 0)
  509.                   WatchDog = TRUE;
  510.             }
  511.          }
  512.          else if(strcmpi(p1,"Colors") == 0) {
  513.             strcpy(temp1,p2);        /* Copy colors numbers */
  514.             p2 = strtok(temp1,", \t");
  515.             for (x=0; x < 7; x++) {
  516.                if (p2) TextAttr[x] = (byte) atoi(p2);
  517.                else {        /* Sysop didn't give full set! */
  518.                   y = TextAttr[x-1];        /* Fetch last attribute */
  519.                   while (x < 7) 
  520.                      TextAttr[x++] = (byte) y;        /* And store to remainder */
  521.                   break;
  522.                }
  523.                p2 = strtok(NULL,", \t");        /* Fetch next token */
  524.             }
  525.          }
  526.          else if (strcmpi(p1,"Bulletin") == 0) {
  527.             if (p2) strcpy(BullFile,p2);
  528.          }
  529.          else if (strcmpi(p1,"DownloadHangup") == 0) {
  530.             if (strcmpi(p2,"STRING") == 0) {
  531.                Hangup = 1;
  532.                HangupMode = 1;
  533.             }
  534.             else if (strcmpi(p2,"DTR") == 0){
  535.                Hangup = 2;
  536.                HangupMode = 2;
  537.             }
  538.             else Hangup = 0;        /* Disable it */
  539.          }
  540.          else if (strcmpi(p1,"MaxDailyCalls") == 0) {
  541.             if (p2) MaxDaily = atoi(p2);
  542.          }
  543.          else if (strcmpi(p1,"ReDirectPacker") == 0) {
  544.             if (p2) {
  545.                if(strcmpi(p2,"yes") == 0)
  546.                   ReDirect = TRUE;
  547.             }
  548.          }
  549.          else if (strcmpi(p1,"UseCommand") == 0) {
  550.             if (p2) {
  551.                if(strcmpi(p2,"yes") == 0)
  552.                   Command = TRUE;
  553.             }
  554.          }
  555.          else if (strcmpi(p1,"StripTags") == 0) {
  556.             if (p2) {
  557.                if(strcmpi(p2,"no") == 0)
  558.                   StripTags = FALSE;
  559.             }
  560.          }
  561.          else if (strcmpi(p1,"QWKWelcome") == 0) {
  562.             if (p2) {
  563.                strcpy(QWKWelcome,p2);
  564.             }
  565.          }
  566.          else if (strcmpi(p1,"QWKnews") == 0) {
  567.             if (p2) {
  568.                strcpy(QWKnews,p2);
  569.             }
  570.          }
  571.          else if (strcmpi(p1,"QWKbye") == 0) {
  572.             if (p2) {
  573.                strcpy(QWKbye,p2);
  574.             }
  575.          }
  576.          else if (strcmpi(p1,"BBSphone") == 0) {
  577.             if (p2) {
  578.                memset(BBSphone,0,15);
  579.                strncpy(BBSphone,p2,14);
  580.             }
  581.          }
  582.          else if (strcmpi(p1,"BBSid") == 0) {
  583.             if (p2) {
  584.                memset(BBSid,0,15);
  585.                strncpy(BBSid,p2,8);
  586.             }
  587.          }
  588.          else if (strcmpi(p1,"RepZip") == 0) {
  589.             if (p2 && ZIPREP == NULL) {
  590.                ZIPREP = (struct reparc_st *) malloc(sizeof(struct reparc_st));
  591.                if (ZIPREP == NULL)
  592.                   aborterror(BADALLOC,NULL);
  593.                ZIPREP->packexe = (char *) malloc(strlen(p2) + 1);
  594.                if (ZIPREP->packexe == NULL)
  595.                   aborterror(BADALLOC,NULL);
  596.                strcpy(ZIPREP->packexe,p2);
  597.                p3 = strtok(NULL," \n\t;");
  598.                if (p3) {
  599.                   p2 = strchr(p3,'_');        /* Look for replacements */
  600.                   while (p2) {
  601.                      *p2 = ' ';                    /* Put a blank instead */
  602.                      p2++;
  603.                      p2 = strchr(p2,'_');        /* Look for replacements */
  604.                   }
  605.                   ZIPREP->packstring = (char *) malloc(strlen(p3) + 1);
  606.                   if (ZIPREP->packstring == NULL)
  607.                      aborterror(BADALLOC,NULL);
  608.                   strcpy(ZIPREP->packstring,p3);
  609.                }
  610.             }
  611.          }
  612.          else if (strcmpi(p1,"RepLha") == 0) {
  613.             if (p2 && LHAREP == NULL) {
  614.                LHAREP = (struct reparc_st *) malloc(sizeof(struct reparc_st));
  615.                if (LHAREP == NULL)
  616.                   aborterror(BADALLOC,NULL);
  617.                LHAREP->packexe = (char *) malloc(strlen(p2) + 1);
  618.                if (LHAREP->packexe == NULL)
  619.                   aborterror(BADALLOC,NULL);
  620.                strcpy(LHAREP->packexe,p2);
  621.                p3 = strtok(NULL," \n\t;");
  622.                if (p3) {
  623.                   p2 = strchr(p3,'_');        /* Look for replacements */
  624.                   while (p2) {
  625.                      *p2 = ' ';                    /* Put a blank instead */
  626.                      p2++;
  627.                      p2 = strchr(p2,'_');        /* Look for replacements */
  628.                   }
  629.                   LHAREP->packstring = (char *) malloc(strlen(p3) + 1);
  630.                   if (LHAREP->packstring == NULL)
  631.                      aborterror(BADALLOC,NULL);
  632.                   strcpy(LHAREP->packstring,p3);
  633.                }
  634.             }
  635.          }
  636.          else if (strcmpi(p1,"RepArc") == 0) {
  637.             if (p2 && ARCREP == NULL) {
  638.                ARCREP = (struct reparc_st *) malloc(sizeof(struct reparc_st));
  639.                if (ARCREP == NULL)
  640.                   aborterror(BADALLOC,NULL);
  641.                ARCREP->packexe = (char *) malloc(strlen(p2) + 1);
  642.                if (ARCREP->packexe == NULL)
  643.                   aborterror(BADALLOC,NULL);
  644.                strcpy(ARCREP->packexe,p2);
  645.                p3 = strtok(NULL," \n\t;");
  646.                if (p3) {
  647.                   p2 = strchr(p3,'_');        /* Look for replacements */
  648.                   while (p2) {
  649.                      *p2 = ' ';                    /* Put a blank instead */
  650.                      p2++;
  651.                      p2 = strchr(p2,'_');        /* Look for replacements */
  652.                   }
  653.                   ARCREP->packstring = (char *) malloc(strlen(p3) + 1);
  654.                   if (ARCREP->packstring == NULL)
  655.                      aborterror(BADALLOC,NULL);
  656.                   strcpy(ARCREP->packstring,p3);
  657.                }
  658.             }
  659.          }
  660.       }
  661.       fgets(temp,81,cfile);
  662.    }
  663.    fclose(cfile);
  664.    return(TRUE);
  665. }
  666.  
  667.  
  668. /* Setup a protocol using string format as follows:
  669.    "Description Filename Commandline"
  670.         |           |          |----------- Command line for program.
  671.         |           |
  672.         |           |---------------------- Full filename (No path)
  673.         |
  674.         |---------------------------------- Desribe protocol in 1-2 words
  675. */
  676.  
  677. void _pascal enable_proto(char *strng)
  678. {
  679.    char cmndline[40];
  680.    char describe[20];
  681.    char fname[14];
  682.    char *p,*p1;
  683.    int x;
  684.    struct proto_st *proto1;
  685.  
  686.  
  687.    p = strtok(strng," \t");        /* Fetch description */
  688.    if (!p)
  689.       return;        /* Invalid */
  690.    p1 = strchr(p,'_');        /* Look for replacements */
  691.    while (p1) {
  692.       *p1 = ' ';                    /* Put a blank instead */
  693.       p1++;
  694.       p1 = strchr(p1,'_');        /* Look for replacements */
  695.    }
  696.    x = strlen(p);
  697.    x = x > 29 ? 29 : x;
  698.    strncpy(describe,p,x);
  699.    describe[x] = '\0';
  700.    
  701.    p = strtok(NULL," \t");        /* Fetch filename */
  702.    if (!p)
  703.       return;        /* Invalid */
  704.    p1 = strchr(p,'_');        /* Look for replacements */
  705.    while (p1) {
  706.       *p1 = ' ';                    /* Put a blank instead */
  707.       p1++;
  708.       p1 = strchr(p1,'_');        /* Look for replacements */
  709.    }
  710.    x = strlen(p);
  711.    x = x > 13 ? 13 : x;
  712.    strncpy(fname,p,x);
  713.    fname[x] = '\0';
  714.    
  715.    p = strtok(NULL," \t");        /* Fetch command line */
  716.    if (!p)
  717.       return;        /* Invalid */
  718.    p1 = strchr(p,'_');        /* Look for replacements */
  719.    while (p1) {
  720.       *p1 = ' ';                    /* Put a blank instead */
  721.       p1++;
  722.       p1 = strchr(p1,'_');        /* Look for replacements */
  723.    }
  724.    x = strlen(p);
  725.    x = x > 39 ? 39 : x;
  726.    strncpy(cmndline,p,x);
  727.    cmndline[x] = '\0';
  728.    
  729.  
  730.    proto1 = (struct proto_st *) malloc(sizeof(struct proto_st));
  731.    if (proto1 == NULL)
  732.       aborterror(BADALLOC,NULL);
  733.  
  734.    if (totprotocols)
  735.       PROTO_cur->next = proto1;
  736.    else PROTO_1 = proto1;
  737.  
  738.    proto1->protoexe = (char *) malloc(strlen(fname) + 1);
  739.    if (proto1->protoexe == NULL)
  740.       aborterror(BADALLOC,NULL);
  741.    strcpy(proto1->protoexe,fname);
  742.  
  743.    proto1->protostring = (char *) malloc(strlen(cmndline) + 1);
  744.    if (proto1->protostring == NULL)
  745.       aborterror(BADALLOC,NULL);
  746.    strcpy(proto1->protostring,cmndline);
  747.  
  748.    proto1->protoname = (char *) malloc(strlen(describe) + 1);
  749.    if (proto1->protoname == NULL)
  750.       aborterror(BADALLOC,NULL);
  751.    strcpy(proto1->protoname,describe);
  752.  
  753.    PROTO_cur = proto1;
  754.    proto1->next = NULL;
  755.  
  756.    totprotocols++;
  757. }
  758.  
  759. /* Setup an upload protocol using string format as follows:
  760.    "Filename Commandline"
  761.         |          |----------- Command line for program.
  762.         |---------------------- Full filename (No path)
  763. */
  764.  
  765. void _pascal enable_upl(char *strng)
  766. {
  767.    char cmndline[40];
  768.    char fname[14];
  769.    char describe[20];
  770.    char *p,*p1;
  771.    int x;
  772.    struct repupl_st *upl1;
  773.  
  774.    p = strtok(strng," \t");        /* Fetch description */
  775.    if (!p)
  776.       return;        /* Invalid */
  777.    p1 = strchr(p,'_');        /* Look for replacements */
  778.    while (p1) {
  779.       *p1 = ' ';                    /* Put a blank instead */
  780.       p1++;
  781.       p1 = strchr(p1,'_');        /* Look for replacements */
  782.    }
  783.    x = strlen(p);
  784.    x = x > 29 ? 29 : x;
  785.    strncpy(describe,p,x);
  786.    describe[x] = '\0';
  787.    
  788.    p = strtok(NULL," \t");        /* Fetch filename */
  789.    if (!p)
  790.       return;        /* Invalid */
  791.    p1 = strchr(p,'_');        /* Look for replacements */
  792.    while (p1) {
  793.       *p1 = ' ';                    /* Put a blank instead */
  794.       p1++;
  795.       p1 = strchr(p1,'_');        /* Look for replacements */
  796.    }
  797.    x = strlen(p);
  798.    x = x > 13 ? 13 : x;
  799.    strncpy(fname,p,x);
  800.    fname[x] = '\0';
  801.    
  802.    p = strtok(NULL," \t");        /* Fetch command line */
  803.    if (!p)
  804.       return;        /* Invalid */
  805.    p1 = strchr(p,'_');        /* Look for replacements */
  806.    while (p1) {
  807.       *p1 = ' ';                    /* Put a blank instead */
  808.       p1++;
  809.       p1 = strchr(p1,'_');        /* Look for replacements */
  810.    }
  811.    x = strlen(p);
  812.    x = x > 39 ? 39 : x;
  813.    strncpy(cmndline,p,x);
  814.    cmndline[x] = '\0';
  815.    
  816.  
  817.    upl1 = (struct repupl_st *) malloc(sizeof(struct repupl_st));
  818.    if (upl1 == NULL)
  819.       aborterror(BADALLOC,NULL);
  820.  
  821.    if (!totuplreps)
  822.       REPUPL_1 = upl1;
  823.    else REPUPL_cur->next = upl1;
  824.  
  825.    upl1->protoexe = (char *) malloc(strlen(fname) + 1);
  826.    if (upl1->protoexe == NULL)
  827.       aborterror(BADALLOC,NULL);
  828.    strcpy(upl1->protoexe,fname);
  829.  
  830.    upl1->protostring = (char *) malloc(strlen(cmndline) + 1);
  831.    if (upl1->protostring == NULL)
  832.       aborterror(BADALLOC,NULL);
  833.    strcpy(upl1->protostring,cmndline);
  834.  
  835.    upl1->protoname = (char *) malloc(strlen(describe) + 1);
  836.    if (upl1->protoname == NULL)
  837.       aborterror(BADALLOC,NULL);
  838.    strcpy(upl1->protoname,describe);
  839.  
  840.    REPUPL_cur = upl1;
  841.    upl1->next = NULL;
  842.  
  843.    totuplreps++;
  844. }
  845.  
  846. /* Setup a packer using string format as follows:
  847.    "Description Filename ArcFname Commandline"
  848.         |           |       |        |------ Command line for program.
  849.         |           |       |
  850.         |           |       |--------------- Name of packed file
  851.         |           |
  852.         |           |---------------------- Full filename (No path)
  853.         |
  854.         |---------------------------------- Desribe packer in 1-2 words
  855. */
  856.  
  857. void _pascal enable_packer(char *strng)
  858. {
  859.    char cmndline[40];
  860.    char viewline[40];
  861.    char describe[20];
  862.    char fname[14];
  863.    char aname[14];
  864.    char *p,*p1;
  865.    int x;
  866.    struct packer_st *pack1;
  867.  
  868.  
  869.    p = strtok(strng," \t");        /* Fetch description */
  870.    if (!p)
  871.       return;        /* Invalid */
  872.    p1 = strchr(p,'_');        /* Look for replacements */
  873.    while (p1) {
  874.       *p1 = ' ';                    /* Put a blank instead */
  875.       p1++;
  876.       p1 = strchr(p1,'_');        /* Look for replacements */
  877.    }
  878.    x = strlen(p);
  879.    x = x > 29 ? 29 : x;
  880.    strncpy(describe,p,x);
  881.    describe[x] = '\0';
  882.    
  883.    p = strtok(NULL," \t");        /* Fetch filename */
  884.    if (!p)
  885.       return;        /* Invalid */
  886.    p1 = strchr(p,'_');        /* Look for replacements */
  887.    while (p1) {
  888.       *p1 = ' ';                    /* Put a blank instead */
  889.       p1++;
  890.       p1 = strchr(p1,'_');        /* Look for replacements */
  891.    }
  892.    x = strlen(p);
  893.    x = x > 13 ? 13 : x;
  894.    strncpy(fname,p,x);
  895.    fname[x] = '\0';
  896.    
  897.    p = strtok(NULL," \t");        /* Fetch packed filename */
  898.    if (!p)
  899.       return;        /* Invalid */
  900.    p1 = strchr(p,'_');        /* Look for replacements */
  901.    while (p1) {
  902.       *p1 = ' ';                    /* Put a blank instead */
  903.       p1++;
  904.       p1 = strchr(p1,'_');        /* Look for replacements */
  905.    }
  906.    x = strlen(p);
  907.    x = x > 13 ? 13 : x;
  908.    strncpy(aname,p,x);
  909.    aname[x] = '\0';
  910.    
  911.    p = strtok(NULL," \t");        /* Fetch command line */
  912.    if (!p)
  913.       return;        /* Invalid */
  914.    p1 = strchr(p,'_');        /* Look for replacements */
  915.    while (p1) {
  916.       *p1 = ' ';                    /* Put a blank instead */
  917.       p1++;
  918.       p1 = strchr(p1,'_');        /* Look for replacements */
  919.    }
  920.    x = strlen(p);
  921.    x = x > 39 ? 39 : x;
  922.    strncpy(cmndline,p,x);
  923.    cmndline[x] = '\0';
  924.    
  925.    viewline[0] = '\0';
  926.    p = strtok(NULL," \t");        /* Fetch viewline */
  927.    if (p) {
  928.       p1 = strchr(p,'_');        /* Look for replacements */
  929.       while (p1) {
  930.          *p1 = ' ';                    /* Put a blank instead */
  931.          p1++;
  932.          p1 = strchr(p1,'_');        /* Look for replacements */
  933.       }
  934.       x = strlen(p);
  935.       x = x > 39 ? 39 : x;
  936.       strncpy(viewline,p,x);
  937.       viewline[x] = '\0';
  938.    }
  939.    
  940.    pack1 = (struct packer_st *) malloc(sizeof(struct packer_st));
  941.    if (pack1 == NULL)
  942.       aborterror(BADALLOC,NULL);
  943.  
  944.    if (totpackers) 
  945.       PACKER_cur->next = pack1;
  946.    else PACKER_1 = pack1;        /* Start up linked list */
  947.  
  948.    pack1->viewstring = NULL;
  949.  
  950.    pack1->packexe = (char *) malloc(strlen(fname) + 1);
  951.    if (pack1->packexe == NULL)
  952.       aborterror(BADALLOC,NULL);
  953.    strcpy(pack1->packexe,fname);
  954.  
  955.    pack1->packstring = (char *) malloc(strlen(cmndline) + 1);
  956.    if (pack1->packstring == NULL)
  957.       aborterror(BADALLOC,NULL);
  958.    strcpy(pack1->packstring,cmndline);
  959.  
  960.    if (viewline[0]) {
  961.       pack1->viewstring = (char *) malloc(strlen(viewline) + 1);
  962.       if (pack1->viewstring == NULL)
  963.          aborterror(BADALLOC,NULL);
  964.       strcpy(pack1->viewstring,viewline);
  965.    }
  966.  
  967.    pack1->packname = (char *) malloc(strlen(describe) + 1);
  968.    if (pack1->packname == NULL)
  969.       aborterror(BADALLOC,NULL);
  970.    strcpy(pack1->packname,describe);
  971.  
  972.    pack1->packpname = (char *) malloc(strlen(aname) + 1);
  973.    if (pack1->packpname == NULL)
  974.       aborterror(BADALLOC,NULL);
  975.    strcpy(pack1->packpname,aname);
  976.  
  977.    PACKER_cur = pack1;
  978.    pack1->next = NULL;
  979.  
  980.    totpackers++;
  981. }
  982.  
  983.  
  984.